package com.guo.core.framework.arrange;

import com.guo.core.framework.template.AbstractExecuteService;
import lombok.extern.slf4j.Slf4j;

@Slf4j
public abstract class ArrangeServiceTemplate extends AbstractExecuteService<ArrangeReq,ArrangeRsp> {

    @Override
    public ArrangeRsp execute(ArrangeReq arrangeReq) {
        ArrangeContext arrangeContext = this.install(arrangeReq);
        ArrangeRsp arrangeRsp = arrangeContext.getArrangeRsp();
        log.info("订单加锁");
        try {
            this.before(arrangeReq);
            this.init(arrangeReq);
            log.info("执行检查逻辑");
            arrangeContext.getCheckChain().check(arrangeReq);
            log.info("执行核心逻辑");
            arrangeContext.getPostChain().post(arrangeReq, arrangeRsp);

            this.after(arrangeContext);

//        } catch(BusinessException be) {

        } catch (Exception e) {

        } finally {
            log.info("订单解锁");
        }

        return arrangeRsp;
    }

    protected abstract ArrangeContext install(ArrangeReq arrangeReq);

    protected abstract void after(ArrangeContext arrangeContext);

    protected abstract void init(ArrangeReq arrangeReq);

    protected abstract void before(ArrangeReq arrangeReq);

}
